package com.cheng.operation.impl;

import com.cheng.common.exception.CommonException;
import com.cheng.data.entity.AcceptInfoEntity;
import com.cheng.data.vo.AcceptInfoVO;
import com.cheng.data.vo.ExceptionVO;
import com.cheng.data.vo.ReqPageInfoVO;
import com.cheng.data.vo.RespPageInfoVO;
import com.cheng.operation.ExceptionOperation;
import com.cheng.service.ExceptionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: ChengJW
 * @date: 2021/11/13 10:17
 * @version: 1.0
 * @description: 异常日志业务逻辑处理类
 */
@Service
public class ExceptionOperationImpl implements ExceptionOperation {

    private final static Logger log = LoggerFactory.getLogger(ExceptionOperationImpl.class);

    @Autowired
    private ExceptionService exceptionService;

    /**
     * @author: ChengJW
     * @params: [map]
     * @return: java.util.List<com.cheng.data.vo.ExceptionVO>
     * @date: 2021/11/13
     * @description: 查询系统异常日志信息，并进行分页
     */
    @Override
    public RespPageInfoVO selectExceptionInfoList(ReqPageInfoVO pageVO) throws CommonException {

        Map<String,Object> map = new HashMap<>();
        if (null == pageVO){
            return null;
        }
        map.put("exUserCode",pageVO.getUserCode());

        if (null != pageVO.getQryReqFir() && !"".equals(pageVO.getQryReqFir())) {
            map.put("exUserName",pageVO.getQryReqFir());
        }
        //开始日期为当天的第一秒
        if(null != pageVO.getStDt() && !"".equals(pageVO.getStDt())) {
            map.put("stDt", pageVO.getStDt()+" 00:00:01");
        }
        //截止日期为当天的最后一秒
        if(null != pageVO.getLmDt() && !"".equals(pageVO.getLmDt())) {
            map.put("lmDt", pageVO.getLmDt()+" 23:59:59");
        }
        PageInfo<ExceptionVO> pageInfo = PageHelper.startPage(pageVO.getPageNum(),pageVO.getPageSize()).doSelectPageInfo(() -> exceptionService.selectExceptionInfoList(map));
        List<ExceptionVO> list = pageInfo.getList();
        RespPageInfoVO respPageInfoVO = new RespPageInfoVO();
        respPageInfoVO.setList(list);
        respPageInfoVO.setPageNum(pageInfo.getPageNum());
        respPageInfoVO.setPageSize(pageInfo.getPageSize());
        respPageInfoVO.setPageCount(pageInfo.getTotal());
        return respPageInfoVO;
    }
}
